package com.du.stutestsys.serverImpl.TeacherManageImpl;

import com.du.stutestsys.dao.SysUserMapper;
import com.du.stutestsys.entity.SysUser;
import com.du.stutestsys.service.TeacherManage.TeacherService;
import com.du.stutestsys.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    SysUserMapper sysUserMapper;
    @Override
    public List<SysUser> selectStu(SysUser sysUser, PageUtil pageUtil) {
        List<SysUser> userList = sysUserMapper.selectStu(sysUser,pageUtil);
        SysUser teaUser = new SysUser();
                userList.forEach(System.out::println);
        if (userList.size()!= 0){   //如果不是根据班级查询，则通过查询出的班级名字查找对应班主任
            System.out.println(userList.get(0).getClass_name());
            teaUser.setClass_name(userList.get(0).getClass_name());
        }
        teaUser.setType("3");  //限定只查询班主任
        List<SysUser> userList1 = sysUserMapper.selectUser(teaUser, pageUtil);
        userList1.forEach(System.out::println);
        //保存班主任老师姓名
        String teachaerName = (userList1.size()>0) ? userList1.get(0).getName(): "邓老师1";
        //查找出的学生集合补充上班主任
        for (SysUser user : userList) {
            user.setTeacher(teachaerName);
        }

        return userList;
    }
}
